package com.yunsom.testdemo.multiple_thread.pipe_stream;

import java.io.IOException;
import java.io.PipedOutputStream;
import java.util.concurrent.TimeUnit;

public class Sender extends Thread{

    private PipedOutputStream pos;

    private int no;

    public Sender(PipedOutputStream pos) {
        super();
        this.pos = pos;
    }

    public void run(){
        try {
            String s;
            s = "hello, user" + no++;
            System.out.println("Sender send :" + s);
            byte[] buf = s.getBytes();
            pos.write(buf, 0, buf.length);
            pos.close();
            TimeUnit.SECONDS.sleep(5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
